package com.company.堆栈队列;

import java.util.Stack;

/**
 * @author Administrator
 */
public class 栈的实现 {
    private int maxSize;
    private long[] stackArray;
    private int top;

    public 栈的实现(int maxSize) {
        this.maxSize = maxSize;
        stackArray = new long[maxSize];
        top = -1;
    }

    // 压栈
    public void push(long i) {
        stackArray[++top] = i;
    }

    // 出栈
    public long pop() {
        return stackArray[top--];
    }

    /**
     * 判断是否为空
     **/
    public boolean isEmpty() {
        return (top == -1);
    }

    public static void main(String[] args) {

        栈的实现 theStack = new 栈的实现(10);
        theStack.push(10);
        theStack.push(20);
        theStack.push(30);
        theStack.push(40);
        theStack.push(50);
        if (!theStack.isEmpty()) {
            while (!theStack.isEmpty()) {
                long pop = theStack.pop();
                System.out.print(pop + " ");
            }
        }
        System.out.println("\n");
        Stack<Integer> stack1 = new Stack<>();
        Stack<Integer> stack2 = new Stack<>();
        stack1.push(1);
        stack1.push(2);
        stack1.push(3);
        stack1.push(4);

        Integer integer = stack1.get(stack1.toArray().length - 1);
        System.out.println("sss "+ integer);


        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }

        }
        while (!stack2.isEmpty()) {
            System.out.print(stack2.pop() + " ");
        }


    }

}


